home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1993 October: Windmill on DISC / ADC Developer CD (1993-10) (''Windmill On DISC'')_iso / Dev.CD Oct 93.iso / System Software / U.S. System Software / System 7 Pro™ Beta 11 / Development Tools / Sample Code / Interprogram Messaging Manager / IPM MessageBoard / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-28  |  2.5 KB  |  162 lines  |  [TEXT/MPS ]

  1. /*-------------------------------------------------------------------------------------
  2.  *
  3.  * IPM MessageBoard AOCE Sample
  4.  *
  5.  * ©1992-1993 Apple Computer
  6.  *
  7.  -------------------------------------------------------------------------------------*/
  8. /*
  9.  * main.c -- main entry point and initialization
  10.  *
  11.  * change history:
  12.  *
  13.  * SJF        2/12/93        1.0b1        udpate to AOCE beta seed
  14.  * SJF        11/6/91        1.0d1        initial coding
  15.  *
  16.  */
  17.  
  18. #ifndef __TYPES__
  19. #include <Types.h>
  20. #endif
  21.  
  22. #ifndef __WINDOWS__
  23. #include <Windows.h>
  24. #endif
  25.  
  26. #ifndef __MENUS__
  27. #include <Menus.h>
  28. #endif
  29.  
  30. #ifndef __FONTS__
  31. #include <Fonts.h>
  32. #endif
  33.  
  34. #ifndef __OSEVENTS__
  35. #include <OSEvents.h>
  36. #endif
  37.  
  38.  
  39. #ifndef __TRAPS__
  40. #include <Traps.h>
  41. #endif
  42.  
  43. #ifndef __GESTALTEQU__
  44. #include <GestaltEqu.h>
  45. #endif
  46.  
  47. #ifndef __OCE__
  48. #include <OCE.h>
  49. #endif
  50.  
  51. #ifndef _GestaltDispatch
  52. #define    _GestaltDispatch    _Gestalt
  53. #endif
  54.  
  55. #include "const.h"
  56. #include "mymenus.h"
  57. #include "globals.h"
  58. #include "utils.h"
  59. #include "trapavailable.h"
  60. #include "myevents.h"
  61. #include "statusdialog.h"
  62. #include "myipm.h"
  63.  
  64. #include "main.h"
  65.  
  66. /* main entry point */
  67.  
  68. void main(void)
  69. {
  70.     InitQueues();
  71.  
  72.     if (DoError(InitToolboxes())==noErr && DoError(InitApplication())==noErr && HasAYS() && DoError(InitIPM())==noErr)
  73.         MainLoop();
  74.             
  75.     if (!HasAYS())
  76.         StopAlert(kNoAYSAlertID,nil);
  77.  
  78.     ExitProgram();
  79.     ExitToShell();
  80. }
  81.  
  82.  
  83. /* initializes the standard Mac toolbox */
  84.  
  85. OSErr InitToolboxes(void)
  86. {
  87.     MaxApplZone();
  88.     MoreMasters();
  89.     MoreMasters();
  90.     MoreMasters();
  91.     InitGraf(&qd.thePort);
  92.     InitFonts();
  93.     InitWindows();
  94.     InitMenus();
  95.     TEInit();
  96.     InitDialogs(nil);
  97.     InitCursor();
  98.     FlushEvents(everyEvent,0L);
  99.         
  100.     return noErr;
  101. }
  102.  
  103.  
  104. /* initializes the application globals/menus/windows/etc... */
  105.  
  106. OSErr InitApplication(void)
  107. {
  108.     // global variable initialization
  109.     
  110.     gHasWaitNextEvent = TrapAvailable(_WaitNextEvent);
  111.         
  112.     gDone = false;
  113.     gInBackground = false;
  114.     
  115.     InitMyMenus();
  116.     InitMyWindows();
  117.     
  118.     return noErr;
  119. }
  120.  
  121.  
  122. void InitMyMenus(void)
  123. {
  124.     Handle mbar;
  125.     MenuHandle appleMenu;
  126.     
  127.     mbar = GetNewMBar(kMenuBarID);
  128.     SetMenuBar(mbar);
  129.     
  130.     appleMenu = GetMenu(kAppleMenu);
  131.     AddResMenu(appleMenu,'DRVR');            // build apple menu
  132.  
  133.     DrawMenuBar();
  134. }
  135.  
  136.  
  137. void InitMyWindows(void)
  138. {
  139.     MakeMainDialog();
  140. }
  141.  
  142.  
  143. // HasAYS
  144. //
  145. // returns true only of AYS is available and running
  146. //
  147. Boolean HasAYS(void)
  148. {
  149.     OSErr err;
  150.     long response;
  151.     
  152.     if (!TrapAvailable(_GestaltDispatch))
  153.         return false;
  154.     
  155.     err = Gestalt(gestaltOCEToolboxAttr,&response);
  156.     if (err!=noErr)
  157.         return false;
  158.         
  159.     return (response && (response << gestaltOCETBAvailable));
  160. }
  161.  
  162.